package com.example.demo;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;

@RestController
public class helloController {
    @RequestMapping("/sayHi")
    public String hello() {
        return "sayHi,StringBoot";
    }

    @RequestMapping("/r3")
    public String r3(Integer name, Integer age) {
        return "name:" + name + ",age:" + age;
    }

    @RequestMapping("/r6")
    public String r6(String[] arr) {
        return Arrays.toString(arr);
    }

    @RequestMapping("/r7")
    public String r7(@RequestParam(value = "list", required = false) List<String> list1){
        if (list1!=null){
            return list1.toString()+",size:"+list1.size();
        }
        return "list为空";
    }

    @RequestMapping("/r8")
    public String r8(@RequestBody(required = false) UserInfo userInfo){
        return userInfo.toString();
    }

    @RequestMapping("/r9/{articleId}")
    public String r9(@PathVariable(required = false) Integer articleId111) {
        return "articleId: " + articleId111;
    }

    @RequestMapping("/r10/{name}/{age}")
    public String r10(@PathVariable Integer age, @PathVariable String name){
        return "name:"+name+",age:"+age;
    }

    @RequestMapping("/getSession")
    public String getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String userName = (String)session.getAttribute("userName");
        return "登录用户:"+userName;
    }

    @RequestMapping("/r11")
    public String getSession11(Integer number1, Integer number2){
        return "" + number1 + number2;
    }
}
